package dev.alm.meituanservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import dev.alm.meituanservice.entity.Category;
import dev.alm.meituanservice.mapper.CategoryMapper;
import dev.alm.meituanservice.service.CategoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Resource
    private CategoryMapper categoryMapper;

    @Override
    public Category addCategory(Category category) {
        int insert = categoryMapper.insert(category);
        if (insert == 0) {
            return null;
        }
        QueryWrapper<Category> wrapper = new QueryWrapper<>();
        wrapper.eq("code", category.getCode());
        return categoryMapper.selectOne(wrapper);
    }

    @Override
    public List<Category> getCategoryList() {
        return categoryMapper.selectList(null);
    }

}
